#include "Def.h"
#include <qgraphicseffect.h>
#include "WidgetFrameLess.h"
#include "WidgetFrameLessPrivate.h"
#include "util.h"

WidgetFrameLess::WidgetFrameLess(QWidget* parent):
QWidget(parent),
d_ptr(new WidgetFrameLessPrivate(this))
{
	//setAttribute(Qt::WA_TranslucentBackground,true);
	setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);// | Qt::ForeignWindow);
	d_ptr->init();

	auto qss = readAllBufferFromFile("..\\config\\skin.qss");
	setStyleSheet(qss);
	d_ptr->setTitleWidgetStyle();

	QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(this);
	shadow->setOffset(0,0);
	shadow->setColor(QColor("#444464"));
	shadow->setBlurRadius(10);
	setGraphicsEffect(shadow);
}

WidgetFrameLess::~WidgetFrameLess()
{
}

void WidgetFrameLess::mousePressEvent(QMouseEvent* e)
{
	if(e->button() == Qt::LeftButton) 
		d_ptr->mousePress = true;
 
	d_ptr->movePoint = e->globalPos() - pos(); 
	update();
}

void WidgetFrameLess::mouseReleaseEvent(QMouseEvent* e)
{
    Q_UNUSED(e)
	d_ptr->mousePress = false;
}

void WidgetFrameLess::mouseMoveEvent(QMouseEvent* e)
{
	if(d_ptr->mousePress && d_ptr->underMouse())   
	{
		QPoint pos = e->globalPos();
		move(pos - d_ptr->movePoint);
	}

	update();
}